<?php
namespace app\beautiful\model\order;
use app\common\model\CommonModel;

class PinTuanOrderModel extends CommonModel{
    protected  $name = 'beautiful_pin_tuan_order';
    protected  $pk   = 'pin_tuan_order_id';
    protected  $type = ['pay_info'         => 'array'  ];
    public function item()
    {
        return $this->hasMany(PinTuanOrderItemModel::class,'pin_tuan_order_id','pin_tuan_order_id');
    }
    
    public function getGroupDjsTimeAttr($value,$data)
    {
        $djs_time=$data['add_time']+86400-time();//一天有效
        return $djs_time>0 ? $djs_time : 0;
    }
    
    public function getDjsTimeAttr($value,$data){
        $t = time();
        $djs = $data['add_time'] + 900 - $t; 
        return  $djs > 0 ?  $djs : 0;
    }

    public function getStatusMeansAttr($value,$data)
    {
        $status_means=[
            1=>'待付款',
            2=>'待成团',
            3=>'已成团',
            -1=>'拼团失败-带退款',
            -2=>'拼团失败-已退款',
            -3=>'取消拼团'
        ];

        return $status_means[$data['status']] ?? '状态异常';
    }
}

